/**
   CS 305 & 503, Data Structures and Algorithms
   Programming Assignment 2, Fall 2010

   A building in a cityscape or skyline.
 */


class Building {

  /**
     The building's left-most extent; leftmostX >= 0.
   */

  final int leftmostX;


  /**
     The building's height; height > 0.
   */

  final int height;


  /**
     The building's width; width > 0.
   */

  final int width;


  /**
   */

  Building(int x, int h, int w) {

    if (x < 0)
      throw new RuntimeException("building's left-most x value is negative");
    if (h < 0)
      throw new RuntimeException("building's height is not positive");
    if (w < 0)
      throw new RuntimeException("building's width is not positive");

    leftmostX = x;
    height = h;
    width = w;
    }


  /**
     Test equality between this building an object.

     @param o The object to test.

     @return True iff this building is equal to o.
   */

  @Override
  public boolean
  equals(Object o) {
    if (o == null)
      return false;
    if (!(o instanceof Building))
      return false;
    final Building b = (Building) o;
    return 
      (b.height == height) && (b.width == width) && (b.leftmostX == leftmostX);
    }


  /**
     Return this building's hash code.

     @return This building's hash code.
   */

  @Override
  public int
  hashCode() {
    return (height + 10)*(width + 100)*(leftmostX + 1000);
    }


  /**
     Convert this building to a string.

     @return This building's string representation.
   */

  @Override
  public String
  toString() {
    return 
      (new StringBuilder("("))
	.append(leftmostX)
	.append(" ")
	.append(height)
	.append(" ")
	.append(width)
	.append(")")
	.toString();
    }



  }


// $Log: Building.java,v $
// Revision 1.3  2010/10/28 22:18:41  rclayton
// Don't use commas in a building's string representation.
//
// Revision 1.2  2010/10/23 03:46:55  rclayton
// Override equals(), hashCode(), toString().
//
// Revision 1.1  2010/10/21 16:06:11  rclayton
// Initial revision
//
